package com.bite.demo.mapper;

import com.bite.demo.model.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserInfoMapper {

    //@Select("select id, username, `password`, age, gender, phone, delete_flag as deleteFlag, " +
     //       "create_time as createTime, update_time as updateTime from userinfo")
    @Select("select * from userinfo")
//    @Results(id = "resultMap", value = {
//            @Result(column ="delete_flag", property ="deleteFlag"),
//            @Result(column ="create_time", property ="createTime"),
//            @Result(column ="update_time", property ="updateTime")
//    })
    List<UserInfo> queryAllUser();
//    @ResultMap(value = "resultMap")
    @Select("select * from userinfo where id=${id}")
    UserInfo queryById(Integer id);
    @Select("select * from userinfo where username = '${username}'")
    List<UserInfo> queryByName(String username);

    @Select("select * from userinfo where id = #{id} and username = #{name}")
    UserInfo queryByIdAndName(Integer id, String name);

    @Select("select * from userinfo where id=#{id}")
    UserInfo queryById2(@Param("id") Integer id);
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into userinfo (username, `password`, age, gender, phone) " +
            " values (#{userInfo.username}, #{userInfo.password}, #{userInfo.age}, #{userInfo.gender}, #{userInfo.phone})")
    Integer insert(@Param("userInfo")UserInfo userInfo);

    @Delete("delete from userinfo where id = #{id}")
    void delete(Integer id);

    @Update("update userinfo set username = #{username} where id = #{id}")
    void update(UserInfo userInfo);

    @Select("select * from userinfo order by id ${sort}")
    List<UserInfo> queryAllUserBySort(String sort);

}
